package org.test.bookpub.dal.sql;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;
import org.test.bookpub.bean.Demo;

public class DemoSqlBuilder {

	public String queryListByCondition(Demo demo) {
		if (demo == null) {
			return "can't query all data from table";
		}
		return new SQL() {
			{
				SELECT("id,name,age");
				FROM("demo");
				if (StringUtils.isNotBlank(demo.getName())) {
					WHERE("name=#{name}");
				}
				if (demo.getAge() != null) {
					WHERE("age=#{age}");
				}
			}
		}.toString();
	}
}
